<?php
//error_reporting(E_ALL);
include_once("../function.php");
include_once('../wechatpay/WxPayPubHelper.php');
include_once("../class/system_class.php");

$_system=new system_class();
$systemparameters=$_system->system_information(1);

//使用通用通知接口
$notify = new Notify_pub($systemparameters);

//存储微信的回调
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
$notify->saveData($xml);

//验证签名，并回应微信。
//对后台通知交互时，如果微信收到商户的应答不是成功或超时，微信认为通知失败，
//微信会通过一定的策略（如30分钟共8次）定期重新发起通知，
//尽可能提高通知的成功率，但微信不保证通知最终能成功。
if($notify->checkSign() == FALSE){
    $notify->setReturnParameter("return_code","FAIL");//返回状态码
    $notify->setReturnParameter("return_msg","签名失败");//返回信息
}else{
    $notify->setReturnParameter("return_code","SUCCESS");//设置返回码
}
$returnXml = $notify->returnXml();
echo $returnXml;

//==商户根据实际情况设置相应的处理流程，此处仅作举例=======


if($notify->checkSign() == TRUE)
{
    if ($notify->data["return_code"] == "FAIL") {

    }
    elseif($notify->data["result_code"] == "FAIL"){

    }
    else{

        $orderid = $notify->data["out_trade_no"];//商户订单号
        $worderid = $notify->data["transaction_id"];//微信交易号
        $wmoney = $notify->data["cash_fee"]/100;//实际交易金额,微信中以分为单位转换为元
        $isgrant = 1;//交易状态已支付

        $sql = "select * from chongzhi where orderid = '".$orderid."' and isgrant = 0";
        $dd = getOne($sql);
        if($dd){
            $sql2 = "update chongzhi set worderid='".$worderid."',wmoney='".$wmoney."',isgrant='".$isgrant."' where orderid = '".$orderid."' and isgrant = 0";
            $save = mysql_query($sql2);
            if($save){
                $sql3 = "select * from member where id = '".$dd['uid']."'";
                $user = getOne($sql3);
                if($user){
                    if($dd['lx'] == 0){
                        //报单币
                        $zsq = $user['zsq']+$dd['jine'];
                        $sql4 = "update member set zsq='".$zsq."' where id='".$dd['uid']."'";
                        mysql_query($sql4);
                    }else if($dd['lx'] == 1){
                        $mey = $user['mey']+$dd['jine'];
                        $sql4 = "update member set mey='".$mey."' where id='".$dd['uid']."'";
                        mysql_query($sql4);
                    }else{
                        //暂无此类型充值 预留
                    }

                }
            }
        }
    }


}

?>
